<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			var schools = [];
			var majors = [];
			function loadSch(){
				var xhr = new XMLHttpRequest();
				xhr.open("GET","depart.json",true);
				xhr.send();
				xhr.onreadystatechange = function(){
					if (xhr.readyState==4 && xhr.status==200) {
						var data  = xhr.responseText; //json文本
						//json文本转换为js的对象
						schools = JSON.parse(data);
						var sc = document.getElementById('sc');
						for (var i=0;i<schools.length;i++) {							
							sc.options[i] = new Option(schools[i].name)
						}
						loadMj();
					}
				}
			}
		</script>
	</head>
	<body onload="loadSch()">
		请选择：学院：<select id="sc" onchange="loadMj()"></select>
		       专业<select id="mj"></select>
		<script>
			function loadMj(){
				var sc = document.getElementById('sc');
				var index = sc.selectedIndex;
				majors = schools[index].major;
				var mj = document.getElementById('mj');
				mj.length = 0;
				for (var i=0;i<majors.length;i++) {
					mj.options[i] = new Option(majors[i])
				}
			}
		</script>
	</body>
</html>
